import type {App} from 'vue'
import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router'
import {createRouterGuards} from './router-guards'
import {LoginRoute, HttpErrorPage} from '@/router/base'
import {indexInfo, fightList, Layout, NullLayout, largeScreen} from '@/router/constant'
import {PageEnum} from '@/enums/pageEnum'
import {vehicleStatistics} from "@/router/constant";

export const routerList = [
    {
        path: PageEnum.BASE_HOME_ITEMS,
        name: PageEnum.BASE_HOME_ITEMS_NAME,
        component: indexInfo,
        meta: {
            title: '区域管理',
            hidden: true
        },
    },
    {
        path: PageEnum.BASE_FIGHT_LIST,
        name: PageEnum.BASE_FIGHT_LIST_NAME,
        component: fightList,
        meta: {
            title: '航班列表',
            hidden: true
        },
    },
    {
        path: PageEnum.BASE_VEHICLE_STATISTICS,
        name: PageEnum.BASE_VEHICLE_STATISTICS_NAME,
        component: vehicleStatistics,
        meta: {
            title: '车辆统计',
            hidden: true
        },
    },
]

const TYPE = import.meta.env.DEV ? import.meta.env.VITE_GLOB_APP_TYPE : window.Z_GLOBAL_CONFIG.VITE_GLOB_APP_TYPE
const TYPE_ROUTERS = () => {
    switch (TYPE) {
        case 'admin':
            return [
                {
                    path: PageEnum.BASE_HOME,
                    name: PageEnum.BASE_HOME_NAME,
                    redirect: PageEnum.BASE_HOME_ITEMS,
                    component: Layout,
                    meta: {
                        title: '中航油后台管理系统',
                        hidden: true
                    },
                    children: [
                        ...routerList
                    ]
                },
            ]
        case 'view':
            return [
                {
                    path: PageEnum.BASE_HOME,
                    name: PageEnum.BASE_HOME_NAME,
                    redirect: PageEnum.VIEW_HOME,
                    component: NullLayout,
                    meta: {
                        title: '中航油后台管理系统',
                        hidden: true
                    },
                    children: [
                        {
                            path: PageEnum.VIEW_HOME,
                            name: PageEnum.VIEW_HOME_NAME,
                            component: largeScreen,
                            meta: {
                                title: '大屏展示',
                                hidden: true
                            },
                        },
                    ]
                },
            ]
        default:
            return [
                {
                    path: PageEnum.BASE_HOME,
                    name: PageEnum.BASE_HOME_NAME,
                    redirect: PageEnum.BASE_HOME_ITEMS,
                    component: Layout,
                    meta: {
                        title: '中航油后台管理系统',
                        hidden: true
                    },
                    children: [
                        ...routerList
                    ]
                },
                {
                    path: PageEnum.VIEW,
                    name: PageEnum.VIEW_NAME,
                    redirect: PageEnum.VIEW_HOME,
                    component: NullLayout,
                    meta: {
                        title: '中航油后台管理系统',
                        hidden: true
                    },
                    children: [
                        {
                            path: PageEnum.VIEW_HOME,
                            name: PageEnum.VIEW_HOME_NAME,
                            component: largeScreen,
                            meta: {
                                title: '大屏展示',
                                hidden: true
                            },
                        },
                    ]
                },
            ]
    }
}
const RootRoute: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'Root',
        redirect: PageEnum.BASE_HOME,
        component: Layout,
        meta: {
            title: '测试页',
            hidden: true
        },
        children: [
            ...HttpErrorPage,
            // modules.indexRoutes,
            // modules.chartRoutes,
            // modules.previewRoutes,
            // modules.editRoutes
        ]
    },
    ...TYPE_ROUTERS()
]

// RedirectRoute
// ReloadRoute
export const constantRouter: any[] = [LoginRoute, ...RootRoute];


const router = createRouter({
    history: createWebHashHistory(''),
    routes: constantRouter,
    strict: true,
})

export function setupRouter(app: App) {
    app.use(router);

    // 创建路由守卫
    createRouterGuards(router)
}

export default router
